package com.zxy.personage.service.impl;


import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxy.common.utils.PageUtils;
import com.zxy.common.utils.Query;

import com.zxy.personage.dao.SubscribeDao;
import com.zxy.personage.entity.SubscribeEntity;
import com.zxy.personage.service.SubscribeService;


@Service("subscribeService")
public class SubscribeServiceImpl extends ServiceImpl<SubscribeDao, SubscribeEntity> implements SubscribeService {

    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<SubscribeEntity> wrapper = new QueryWrapper<>();
        String hid = (String) params.get("hid");
        if (hid!=null&&hid!=""){
            int s = Integer.parseInt(hid);
            wrapper.eq("hid",s);
        }
        String ytype = (String) params.get("ytype");
        if (StringUtils.isNotEmpty(ytype)){

            wrapper.eq("ytype",ytype);
        }
            IPage<SubscribeEntity> page = this.page(
                    new Query<SubscribeEntity>().getPage(params),
                    wrapper
            );
        return new PageUtils(page);
    }

    @Override
    public SubscribeEntity getId(Integer yid) {
        SubscribeEntity subscribe = baseMapper.selectById(yid);
        subscribe.setStatus(1);
        baseMapper.updateById(subscribe);
        return subscribe;
    }

}